package com.busi.controller.activityplan;
import com.busi.model.ActivityPlan;
import com.busi.model.Goods;
import com.busi.util.GsonUtils;
import com.busi.util.HttpUtils;
import com.busi.util.PropertyUtil;
import com.busi.util.StringUtil;
import com.google.gson.Gson;
import com.zcurd.controller.BaseController;

/** ******************  类说明  *********************
 * class       :  ActivityPlanController
 * @author     :  zs
 * @version    :  1.0  
 * description :  积分夺宝明细
 * @see        :                        
 * 
 * ************************************************/


public class ActivityPlanController extends BaseController {

	
	public void listPage(){
		render("list.html");
	}
	public void addPage(){
		
	     
	}
//	public void updatePage(){
//		render("update.html");
//	}
    
/*	*//**
	 *//*
	public void listData() {
		ActivityPlan activityPlan = getBean(ActivityPlan.class, "");
		String body = gson.toJson(activityPlan);
		String domain = PropertyUtil.getStrValue("indiana.domain", "");
		String url = domain + "/indiana/admin/activityPlan/listbypage";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
		renderJson(jsonString==null?"":jsonString);		
	}*/
	
	/**
	 */
	
	/**
	 * 查询mall-service商品线上表数据
	 */
	public void listOnline() {		
		Goods goods = getBean(Goods.class, "");
		String body = gson.toJson(goods);
		String domain = PropertyUtil.getStrValue("mall.domain", "");
		String url = domain + "/emall/admin/goodsonline/listbypage";
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
		renderJson(jsonString==null?"":jsonString);		
	}
	
//	public List<ActivityPlan> findAll(){
//		HttpUtils.doGet(url, headers, connectionTimeout, readTimeout, charset);
//		gson.fromJson();
//		return null;
//	}
	/**
	 * 查询单条数据
	 * */
	public void updatePage() {			  
		String productid = super.getPara("productid");
		LOG.info("#updatePage()请求参数:"+productid);
		String domain = PropertyUtil.getStrValue("mall.domain", "");
		String url = domain + "/emall/admin/goodsonline/listTwo"+productid;
		String jsonString = HttpUtils.doGet(url, null , 3, 5, "utf-8");
		Gson gson = GsonUtils.buildGsonObject();
		Goods g = gson.fromJson(jsonString, Goods.class);
		setAttr("goods", g);
		if(g!=null){
			render("add.html");		
		}else{
			render("add2.html");		
		}
			
	}
	
	
	//增加
	public void add() {
//		String goodsid = super.getPara("goodsid");
		
		ActivityPlan activityPlan = getBean(ActivityPlan.class, "activityPlan");		
		
	
		String body = gson.toJson(activityPlan);
		LOG.info("#add()请求参数:==============="+body);
		String domain = PropertyUtil.getStrValue("indiana.domain", "");
		
		String url = domain + "/indiana/admin/activityPlan/add";
		String[][] headers = {{"Content-Type", "application/json"}};
		String ret = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
//		if ("success".equals(ret)){
			renderSuccess();
//			return;
//		}
//		renderJson(ret==null?"":ret);
//		String rad= request.getParameter("");
//		renderText("添加成功");
	}
	
	
	
	//动态加载商品名称
	public void getGoodsName() {
		/*String goodsname = getPara("goodsname");*/
		ActivityPlan activityPlan = getBean(ActivityPlan.class, "");		
		String body = gson.toJson(activityPlan);
		LOG.info("#getGoodsName()请求参数"+activityPlan.getGoodsname());
		if(StringUtil.isNotBlank(activityPlan.getGoodsname())){
			String domain = PropertyUtil.getStrValue("indiana.domain", "");
			String url = domain + "/indiana/admin/activityPlan/getGoodsName";
			String[][] headers = {{"Content-Type", "application/json"}};
			String ret = HttpUtils.doPost(url,body,headers, 3,10 , "utf-8");
			LOG.info("#getGoodsName()响应参数========================="+ret);
			renderJson(ret);
		}
	
	}
}
